package model.commands.misc;

import java.util.List;
import java.util.Map;
import model.Environment;
import model.SyntaxErrorException;
import model.commands.Command;

/**
 * Name:
 * MAKE variable value
 * SET variable value
 * 
 * Description:
 * assigns value to variable, creating the variable if necessary
 * returns value
 * 
 * @author JLongley
 * @author Erick Gonzalez
 */
public class MakeCommand extends Command {
    private Map<String, Integer> myVariables;
    private String myVarName;     
    
    /**
     * 
     * @param variables a mapping from variable name to variable value in the current scope
     * @param varName a variable name
     */
    public MakeCommand(Map<String, Integer> variables, String varName) {
        myVariables = variables;
        myVarName = varName;        
    }

    @Override
    public int evaluate(Environment e) throws SyntaxErrorException {
        List<Command> myArguments = getArguments();        
        int value = myArguments.get(0).evaluate(e);
        myVariables.put(myVarName, value);
        return value;
    }

}
